var e = getApp();

Page({
    data: {
        language: "",
        content: "",
        order_id: "",
        goods_id: "",
        order_goods_id: "",
        created_at: "",
        append: null,
        reply: null,
        head_img_url: "",
        images: [],
        nick_name: "",
        level_name: "",
        has_one_order_goods: null,
        has_many_reply: [],
        comment_id: "",
        reply_type: 1,
        reply_placeholder: "回复@昵称:",
        reply_one: "",
        uid: "",
        level: 0,
        worker_score: null,
        worker_name: "安装师傅"
    },
    onLoad: function(e) {
        e.order_id && this.setData({
            order_id: e.order_id
        }), e.goods_id && this.setData({
            goods_id: e.goods_id
        }), e.order_goods_id && this.setData({
            order_goods_id: e.order_goods_id
        }), e.comment_id && this.setData({
            comment_id: e.comment_id
        }), e.uid && this.setData({
            uid: e.uid
        }), this._getNetData();
    },
    onReady: function() {
        var e = wx.getStorageSync("langIndex");
        this.setData({
            language: e.en
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    previewImage: function(e) {
        var t = e.currentTarget.dataset, a = t.images, o = t.src;
        wx.previewImage({
            current: o,
            urls: a
        });
    },
    onShareTimeline: function() {
        var e = {
            title: "评价详情",
            query: "/packageD/member/CommentDetails/CommentDetails?"
        };
        return e.query += "order_id=".concat(this.data.order_id, "&goods_id=").concat(this.data.goods_id, "&order_goods_id=").concat(this.data.order_goods_id, "&comment_id=").concat(this.data.comment_id), 
        this.data.uid && (e.query += "&uid=".concat(this.data.uid)), this.data.istype && (e.query += "&istype=".concat(this.data.istype)), 
        e;
    },
    onShareAppMessage: function() {
        var e = {
            title: "评价详情",
            path: "/packageD/member/CommentDetails/CommentDetails?"
        };
        return e.path += "order_id=".concat(this.data.order_id, "&goods_id=").concat(this.data.goods_id, "&order_goods_id=").concat(this.data.order_goods_id, "&comment_id=").concat(this.data.comment_id), 
        this.data.uid && (e.path += "&uid=".concat(this.data.uid)), this.data.istype && (e.path += "&istype=".concat(this.data.istype)), 
        e;
    },
    _getNetData: function() {
        var t = this, a = this, o = e.getNetAddresss("goods.comment.get-order-goods-comment");
        o += "&order_id=" + this.data.order_id, o += "&goods_id=" + this.data.goods_id, 
        o += "&order_goods_id=" + this.data.order_goods_id, o += "&comment_id=" + this.data.comment_id, 
        e._getNetWork({
            url: o,
            success: function(e) {
                var o = e.data;
                if (1 == o.result) {
                    var n = o.data;
                    a.setData({
                        content: n.content,
                        created_at: n.created_at,
                        append: n.append,
                        reply: n.reply_name,
                        head_img_url: n.head_img_url,
                        images: n.images,
                        nick_name: n.nick_name,
                        level_name: n.level_name,
                        has_one_order_goods: n.has_one_order_goods,
                        has_many_reply: n.has_many_reply,
                        comment_id: n.id,
                        level: n.level
                    }), n.has_one_live_install_comment && n.has_one_live_install_comment.worker_score && t.setData({
                        worker_score: n.has_one_live_install_comment.worker_score
                    }), n.another_name && n.another_name.worker_name && t.setData({
                        worker_name: n.another_name.worker_name
                    });
                } else wx.showToast({
                    icon: "none",
                    title: o.msg,
                    duration: 1e3
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    submitReplyForComment: function() {
        this.setData({
            reply_type: 1,
            reply_placeholder: "回复@昵称:主评论"
        });
    },
    replyToSomeOne: function(e) {
        var t = e.target.dataset.item;
        this.setData({
            reply_type: 2,
            reply_one: t,
            reply_placeholder: "回复@昵称:" + t.nick_name
        });
    },
    replyContentBtn: function(e) {
        var t = e.detail.value;
        this.setData({
            reply_content: t
        });
    },
    submitReply: function() {
        var t = this, a = "";
        a = 1 == this.data.reply_type ? this.data.comment_id : this.data.reply_one.id;
        var o = e.getNetAddresss("goods.comment.reply-comment");
        o += "&id=" + a, o += "&content=" + this.data.reply_content, e._getNetWork({
            url: o,
            success: function(e) {
                var a = e.data;
                if (1 == a.result) {
                    var o = a.data, n = t.data.has_many_reply;
                    n.push(o), t.setData({
                        reply_content: "",
                        has_many_reply: n
                    });
                } else wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1e3
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    toGoods: function(e) {
        var t = e.currentTarget.dataset.goodsid;
        wx.redirectTo({
            url: "/packageA/detail_v2/detail_v2?id=" + t
        });
    }
});